package com.qk.management.controller;

import com.qk.common.PageResult;
import com.qk.common.Result;
import com.qk.common.constant.ClueStatusConstants;
import com.qk.domain.clue.ClueDO;
import com.qk.dto.clue.ClueDTO;
import com.qk.dto.clue.ClueListDTO;
import com.qk.dto.clue.UpdateClueInfoDTO;
import com.qk.entity.Clue;
import com.qk.management.aop.anno.LogAnno;
import com.qk.management.service.ClueService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.qk.vo.clue.ClueVO;

import java.time.LocalDateTime;

@RestController
@RequestMapping("/clues")
public class ClueController {


    @Autowired
    private ClueService clueService;

    @GetMapping
    public Result listClue( ClueListDTO dto) {
        PageResult<ClueDO> pageResult = clueService.listClue(dto);
        return Result.success(pageResult);
    }

    @LogAnno
    @PostMapping
    public Result addClue(@RequestBody ClueDTO dto) {
        clueService.addClue(dto);
        return Result.success();
    }

    @LogAnno
    @PutMapping("/assign/{clueId}/{userId}")
    public Result updateClueById(@PathVariable Integer clueId, @PathVariable Integer userId) {
        clueService.updateById(Clue.builder()
                .id(clueId)
                .userId(userId)
                .updateTime(LocalDateTime.now())
                .status(ClueStatusConstants.WAIT_FOLLOW_UP)
                .build());
        return Result.success();
    }

    @GetMapping("/{id}")
    public Result getClueInfoById(@PathVariable Integer id){
        ClueVO vo= clueService.getClueInfoById(id);
        return Result.success(vo);
    }

    @LogAnno
    @PutMapping
    public Result updateClueInfoById(@RequestBody UpdateClueInfoDTO dto) {

        clueService.updateClueInfoById(dto);
        return Result.success();
    }

    @LogAnno
    @PutMapping("toBusiness/{id}")
    public Result toBusiness(@PathVariable Integer id) {
        clueService.toBusiness(id);
        return Result.success();
    }

    @LogAnno
    @PutMapping("/false/{id}")
    public Result falseClue(@PathVariable Integer id) {
        clueService.falseClue(id);
        return Result.success();
    }

    //线索池列表查询
    @GetMapping("/pool")
    public Result listCluePool(ClueListDTO dto) {
        PageResult<ClueDO> pageResult = clueService.listClue(dto);
        return Result.success(pageResult);
    }
}
